﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Net;

namespace VLCMultyRemote
{
    /// <summary>
    /// Interaktionslogik für IPAndPortInputWindow.xaml
    /// </summary>
    public partial class AddClientWindow : Window
    {

        /// <summary>
        /// list of clients
        /// </summary>
        private ObservableCollection<Client> clients;

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="clients">a list of clients, need to add one client</param>
        public AddClientWindow(ObservableCollection<Client> clients)
        {
            InitializeComponent();
            this.clients = clients;
        }

        /// <summary>
        /// check the inputs and add the client to the client-list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                clients.Add(new Client(new IPEndPoint(Dns.GetHostAddresses(textBoxIP.Text)[0], int.Parse(textBoxPort.Text)), textBoxName.Text));
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                textBoxPort.Text = null;
                textBoxIP.Text = null;
                return;
            }

            this.Close();
        }

        /// <summary>
        /// cancel the process and close this window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
